﻿using System.IO;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace Library.WebControls.SimpleCombobox {
	public class SpComboboxDesign : ControlDesigner {
		public override string GetDesignTimeHtml()
		{
			
			return GetDesignTimeHtml((SpCombobox)Component);
		}

		internal static string GetDesignTimeHtml(SpCombobox cbx) {
			var sw = new StringWriter();
			var tw = new HtmlTextWriter(sw);
			var divCombobox = new HtmlGenericControl("div");
			divCombobox.Attributes["class"] = SpCombobox.ComboboxCss;
			var divInputImagePanel = new HtmlGenericControl("div");
			divInputImagePanel.Attributes["class"] = SpCombobox.InputImagePanelCss;
			divCombobox.Controls.Add((divInputImagePanel));

			var textBox = new TextBox();
			textBox.MergeStyle(cbx.TextEdit.ControlStyle);
			textBox.Text = cbx.TextEdit.Text;
			divInputImagePanel.Controls.Add(textBox);
			var image = new Image();
			image.MergeStyle(cbx.ImageButton.ControlStyle);
			image.ImageUrl = cbx.ImageButton.ImageUrl;
			image.Width = cbx.ImageButton.Width;
			image.Height = cbx.ImageButton.Height;
			divInputImagePanel.Controls.Add((image));
			cbx.CreateCssLink().RenderControl(tw);
			divCombobox.RenderControl(tw);

			return sw.ToString();
		}
	}
}
